<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>engine.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_labs_useragent_engine.js.html">engine.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2013 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Closure user agent detection.
<a name="line17"></a> * @see http://en.wikipedia.org/wiki/User_agent
<a name="line18"></a> * For more information on browser brand, platform, or device see the other
<a name="line19"></a> * sub-namespaces in goog.labs.userAgent (browser, platform, and device).
<a name="line20"></a> *
<a name="line21"></a> */
<a name="line22"></a>
<a name="line23"></a>goog.provide(&#39;goog.labs.userAgent.engine&#39;);
<a name="line24"></a>
<a name="line25"></a>goog.require(&#39;goog.array&#39;);
<a name="line26"></a>goog.require(&#39;goog.labs.userAgent.util&#39;);
<a name="line27"></a>goog.require(&#39;goog.string&#39;);
<a name="line28"></a>
<a name="line29"></a>
<a name="line30"></a>/**
<a name="line31"></a> * @return {boolean} Whether the rendering engine is Presto.
<a name="line32"></a> */
<a name="line33"></a>goog.labs.userAgent.engine.isPresto = function() {
<a name="line34"></a>  return goog.labs.userAgent.util.matchUserAgent(&#39;Presto&#39;);
<a name="line35"></a>};
<a name="line36"></a>
<a name="line37"></a>
<a name="line38"></a>/**
<a name="line39"></a> * @return {boolean} Whether the rendering engine is Trident.
<a name="line40"></a> */
<a name="line41"></a>goog.labs.userAgent.engine.isTrident = function() {
<a name="line42"></a>  // IE only started including the Trident token in IE8.
<a name="line43"></a>  return goog.labs.userAgent.util.matchUserAgent(&#39;Trident&#39;) ||
<a name="line44"></a>      goog.labs.userAgent.util.matchUserAgent(&#39;MSIE&#39;);
<a name="line45"></a>};
<a name="line46"></a>
<a name="line47"></a>
<a name="line48"></a>/**
<a name="line49"></a> * @return {boolean} Whether the rendering engine is WebKit.
<a name="line50"></a> */
<a name="line51"></a>goog.labs.userAgent.engine.isWebKit = function() {
<a name="line52"></a>  return goog.labs.userAgent.util.matchUserAgentIgnoreCase(&#39;WebKit&#39;);
<a name="line53"></a>};
<a name="line54"></a>
<a name="line55"></a>
<a name="line56"></a>/**
<a name="line57"></a> * @return {boolean} Whether the rendering engine is Gecko.
<a name="line58"></a> */
<a name="line59"></a>goog.labs.userAgent.engine.isGecko = function() {
<a name="line60"></a>  return goog.labs.userAgent.util.matchUserAgent(&#39;Gecko&#39;) &amp;&amp;
<a name="line61"></a>      !goog.labs.userAgent.engine.isWebKit() &amp;&amp;
<a name="line62"></a>      !goog.labs.userAgent.engine.isTrident();
<a name="line63"></a>};
<a name="line64"></a>
<a name="line65"></a>
<a name="line66"></a>/**
<a name="line67"></a> * @return {string} The rendering engine&#39;s version or empty string if version
<a name="line68"></a> *     can&#39;t be determined.
<a name="line69"></a> */
<a name="line70"></a>goog.labs.userAgent.engine.getVersion = function() {
<a name="line71"></a>  var userAgentString = goog.labs.userAgent.util.getUserAgent();
<a name="line72"></a>  if (userAgentString) {
<a name="line73"></a>    var tuples = goog.labs.userAgent.util.extractVersionTuples(
<a name="line74"></a>        userAgentString);
<a name="line75"></a>
<a name="line76"></a>    var engineTuple = tuples[1];
<a name="line77"></a>    if (engineTuple) {
<a name="line78"></a>      // In Gecko, the version string is either in the browser info or the
<a name="line79"></a>      // Firefox version.  See Gecko user agent string reference:
<a name="line80"></a>      // http://goo.gl/mULqa
<a name="line81"></a>      if (engineTuple[0] == &#39;Gecko&#39;) {
<a name="line82"></a>        return goog.labs.userAgent.engine.getVersionForKey_(
<a name="line83"></a>            tuples, &#39;Firefox&#39;);
<a name="line84"></a>      }
<a name="line85"></a>
<a name="line86"></a>      return engineTuple[1];
<a name="line87"></a>    }
<a name="line88"></a>
<a name="line89"></a>    // IE has only one version identifier, and the Trident version is
<a name="line90"></a>    // specified in the parenthetical.
<a name="line91"></a>    var browserTuple = tuples[0];
<a name="line92"></a>    var info;
<a name="line93"></a>    if (browserTuple &amp;&amp; (info = browserTuple[2])) {
<a name="line94"></a>      var match = /Trident\/([^\s;]+)/.exec(info);
<a name="line95"></a>      if (match) {
<a name="line96"></a>        return match[1];
<a name="line97"></a>      }
<a name="line98"></a>    }
<a name="line99"></a>  }
<a name="line100"></a>  return &#39;&#39;;
<a name="line101"></a>};
<a name="line102"></a>
<a name="line103"></a>
<a name="line104"></a>/**
<a name="line105"></a> * @param {string|number} version The version to check.
<a name="line106"></a> * @return {boolean} Whether the rendering engine version is higher or the same
<a name="line107"></a> *     as the given version.
<a name="line108"></a> */
<a name="line109"></a>goog.labs.userAgent.engine.isVersionOrHigher = function(version) {
<a name="line110"></a>  return goog.string.compareVersions(goog.labs.userAgent.engine.getVersion(),
<a name="line111"></a>                                     version) &gt;= 0;
<a name="line112"></a>};
<a name="line113"></a>
<a name="line114"></a>
<a name="line115"></a>/**
<a name="line116"></a> * @param {!Array.&lt;!Array.&lt;string&gt;&gt;} tuples Version tuples.
<a name="line117"></a> * @param {string} key The key to look for.
<a name="line118"></a> * @return {string} The version string of the given key, if present.
<a name="line119"></a> *     Otherwise, the empty string.
<a name="line120"></a> * @private
<a name="line121"></a> */
<a name="line122"></a>goog.labs.userAgent.engine.getVersionForKey_ = function(tuples, key) {
<a name="line123"></a>  // TODO(nnaze): Move to util if useful elsewhere.
<a name="line124"></a>
<a name="line125"></a>  var pair = goog.array.find(tuples, function(pair) {
<a name="line126"></a>    return key == pair[0];
<a name="line127"></a>  });
<a name="line128"></a>
<a name="line129"></a>  return pair &amp;&amp; pair[1] || &#39;&#39;;
<a name="line130"></a>};
</pre>


</body>
</html>
